from appium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


class Base():
    def __init__(self):
        cap={
            "platformName": "Android",
            "deviceName": "127.0.0.1:7555",
            "noReset": True,
            "appPackage": "cn.xuexi.android",
            "appActivity": "com.alibaba.android.rimet.biz.home.activity.HomeActivity"
        }
        #连接
        self.devices=webdriver.Remote('http://127.0.0.1:4723/wd/hub',cap)
        #隐式等待
        self.devices.implicitly_wait(15)
    def find_loc(self,loc):
        ele=self.devices.find_element(*loc)
        return ele
    #显示等待
    def find_wait(self,loc):
        ele=WebDriverWait(self.devices,100).until(EC.element_to_be_clickable(loc))
        return ele
    def huadong(self,a,b,c,d):
        self.devices.swipe(a,b,c,d)
    def qiangqiao(self,a,b):
        self.devices.tap([(a,b)],100)
    def tuichu(self):
        self.devices.quit()
    def jietu(self,a):
        self.devices.save_screenshot(a)